<?php
/**
 * @Author: xuzhiyi
 * @Date:   2016-02-16 20:57:18
 * @Last Modified by:   xuzhiyi
 * @Last Modified time: 2016-03-03 17:19:07
 * ------------------------------------------------ *
 * 文章                                         *
 * ------------------------------------------------ */

namespace Admin\Controller;
class ArticlesController extends CommonController {

	public function index() {
		if (IS_AJAX) {
			switch (I('ajax')) {
				case "isShow":
					$status = D('Articles')->editStatus();
					$this->ajaxReturn($status);
					break;
				case "delArticles":
					$status = D('Articles')->delArticles();
					$this->ajaxReturn($status);
					break;
				case "editArticles":
					if (I('articleId', 0) > 0) {
						$a = D('Articles')->editArticles();
						if ($a) {
							$this->success('文章修改成功！', '', true);
						}
						$this->error('文章修改失败！', '', true);
					} else {
						$a = D('Articles')->addArticles();
						if ($a) {
							$this->success('文章添加成功！', '', true);
						}
						$this->error('文章添加失败！', '', true);
					}
					break;
				default:
					$output = D('Articles')->getArticles();
					$this->ajaxReturn($output);

			}
		}

		$this->display();
	}

	public function edit() {
		$articles = D('Articles')->get();
		$this->assign('articles', $articles);
		$articleCats = D('ArticleCats')->getArticleCats();
		$this->assign('articleCats', $articleCats['data']);
		$this->display();
	}
}